package net.uhuijia.shop.usershop.service.impl;

import net.uhuijia.shop.info.persistence.model.Shop;
import net.uhuijia.shop.usershop.service.UserShopService;
import net.uhuijia.user.usermall.persistence.model.UserMall;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import net.uhuijia.appbase.service.CrudService;
import net.uhuijia.shop.usershop.persistence.dao.UserShopDao;
import net.uhuijia.shop.usershop.persistence.model.UserShop;
import net.uhuijia.shop.usershop.persistence.model.UserShopExample;

import java.util.List;


@Service
@Transactional
public class UserShopServiceImpl
     extends CrudService<UserShopDao,UserShop,UserShopExample> implements UserShopService {
    @Autowired
    private UserShopDao userShopDao;

    /**
     * 根据userId  查询用户是否申请了店铺信息
     * @param userId
     * @return
     */
    @Override
    public List<UserShop> findUserShopByUserId(String userId) {
        if(StringUtils.isEmpty(userId))
            throw new IllegalArgumentException();
        List<UserShop> userShops = this.userShopDao.findUserShopByUserId(userId);
        return userShops;
    }
    /**
     * @Author xzj
     * @Description //用户绑定店铺
     * @Date  2018/10/7
     * @Param
     * @return
     **/
    @Override
    public String addUserShop(UserMall userMall, Shop shop) {
        UserShop userShop = new UserShop();
        userShop.setUserId(userMall.getId());
        userShop.setNickName(userMall.getNickName());
        userShop.setShopId(shop.getId());
        userShop.setShopName(shop.getShopName());
        return this.add(userShop);
    }
}